package app.kotlin_1.base

import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

/**
 * Created by 刘智强 on 2017/9/19.
 */
abstract class BaseFragment : Fragment(), View.OnClickListener {

    var context: Activity? = null
    var rootView: View? = null;
    override fun onAttach(context: Context?) {
        super.onAttach(context)
        this.context = activity
    }

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
        rootView = inflater!!.inflate(getLayoutId(), container, false)
        initView(rootView!!)
        initData()
        initListener()
        setData()
        return rootView!!
    }

    abstract fun getLayoutId(): Int
    abstract fun initData()
    abstract fun initView(v: View)
    abstract fun initListener()
    abstract fun setOnClick(v: View?)

    abstract fun requestData()
    abstract fun setData()


    override fun onClick(v: View?) {
        setOnClick(v)

    }

    override fun onResume() {
        super.onResume()
        requestData()
    }

    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        if (!hidden) {
            requestData()
        }
    }


}